package com.atguigu.lease.web.app.controller.history;


import com.atguigu.lease.common.jwt.JwtUtil;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.web.app.service.BrowsingHistoryService;
import com.atguigu.lease.web.app.service.LoginService;
import com.atguigu.lease.web.app.vo.history.HistoryItemVo;
import com.atguigu.lease.web.app.vo.user.UserInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {

    @Autowired
    private BrowsingHistoryService browsingHistoryService;
    @Autowired
    private LoginService loginService;
    @Operation(summary = "获取浏览历史")
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size, @RequestHeader("access_token") String accessToken) {
        //解析 token 获取 Claims
        Claims claims = JwtUtil.parseToken(accessToken);
        Long userId = claims.get("userId", Long.class); // 从 token 中提取 userId

        Page<HistoryItemVo>page=new Page<>(current,size);
        browsingHistoryService.customPage(page,userId);
        return Result.ok(page);
    }

}
